<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="renderer" content="webkit" />
	<meta http-equiv="X-UA-COMPATIBLE" content="IE=edge,chrome=1"/>
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<title>{$title_name}</title>
	<meta name="keywords" content="{$title_name}" />
	<meta name="description" content="{$title_name}" />
	<meta name="author" content="{$title_name}网站" />
	<link rel="shortcut  icon" type="image/x-icon" href="__STATIC__/images/favicon.ico" media="screen"/>
	<script src="__STATIC__/js/jquery-1.8.1.min.js"></script>
	<script src="__STATIC__/bootstrap/js/bootstrap.js"></script>
	<link href="ADMIN_CSS/new_member_login.css" rel="stylesheet" type="text/css" />
</head>
<body>
{include file="admin/urlModel"}
{include file="admin/controlCommonVariable" }
<div class="admin-login-box">
	<div class="login-content-area">
		<div class="w1100">
			<div class="left-logo-area">
	<!-- 			<a href="{:__URL('SHOP_MAIN/index')}" class="logo-img"> -->
	<!-- 				<img src="ADMIN_IMG/login-logo.png" alt="" /> -->
	<!-- 			</a> -->

			</div>
			<div class="right-login-area">
				<form action="javascript:;">
					<div class="login-logo">
						管理后台登录
					</div>
					<div class="tip_info">
						<div class="prompt_information" id="hint">
							账号密码错误
						</div>
					</div>
					<!-- 用户名 -->
					<div class="user-name-box">
						<div class="username_bg" ></div>
						<input type="text" placeholder="请输入账号" id="txtName"/>
					</div>
					<!-- 密码框 -->
					<div class="password-box">
						<div class="password_bg" ></div>
						<input type="password" placeholder="请输入密码" id="txtPWD"/>
					</div>
					<!-- 验证码 -->
					<div class="verification-code-box" {if condition="!$is_need_verification"}style="display:none;"{/if}>
						<input type="text" placeholder="请输入验证码" id="vertification"/>
						<div class="verification-code-img">
							<img id="verify_img" src="{:__URL('SHOP_MAIN/captcha')}" alt="captcha" onclick="this.src='{:__URL('SHOP_MAIN/captcha?tag=1')}'+'&send='+Math.random()" />
						</div>
					</div>
					<input type="button" value="登录" class="sub_login" onclick="btnlogin();" />
				</form>
			</div>
		</div>
	</div>
</div>
<script>
$(function(){
	ini_margin_top();
});

window.onresize = function(){
	ini_margin_top();
};

function ini_margin_top(){
	var admin_login_box_height = $(".admin-login-box").height();
	var login_content_area_height = 590;
	var margin_top = (admin_login_box_height - login_content_area_height)/2;
	$(".login-content-area").css("margin", margin_top+"px auto 0 auto");
	if(admin_login_box_height < 800){
		$(".txt").hide();
	}else{
		$(".txt").show();
	}
}

// enter 键登录
document.onkeypress = function() {
	var iKeyCode = -1;
	if (arguments[0]) {
		iKeyCode = arguments[0].which;
	} else {
		iKeyCode = event.keyCode;
	}
	if (iKeyCode == 13) {
		// 登录
		$(".sub_login").click();
	}
};

//键盘tab
$(document).keyup(function(e){
    var key =  e.which;
    if(key == 9){
        check_is_focus();
    }
});

$("body").click(function(){
	check_is_focus();
});

function check_is_focus(){
	if($("#txtName").is(":focus")){
		$("#txtName").parent("div").css("border-color","#0072D3");
	}else{
		$("#txtName").parent("div").css("border-color","#D9D9D8");
	}
	if($("#txtPWD").is(":focus")){
		$("#txtPWD").parent("div").css("border-color","#0072D3");
	}else{
		$("#txtPWD").parent("div").css("border-color","#D9D9D8");
	}
	if($("#vertification").is(":focus")){
		$("#vertification").parent("div").css("border-color","#0072D3");
	}else{
		$("#vertification").parent("div").css("border-color","#D9D9D8");
	}
}

// 登陆 登录时 登录按钮"变暗"
function btnlogin() {
	ClearCookie(); //登录时清除之前的cookie
	if ($("#txtName").val() == "") {
		$("#hint").css("display", "block").text("请输入账号");
		$("#txtName").focus();
		return false;
	} else if ($("#txtPWD").val() == "") {
		$("#hint").css("display", "block").text("请输入密码");
		$("#txtPWD").focus();
		return false;
	}
	var userName = $('#txtName').val();
	var password = $('#txtPWD').val();
	var vertification = $("#vertification").val();

	if(!$(".verification-code-box").is(":hidden")){
		if($("#vertification").val() == undefined || $("#vertification").val() == ""){
			$("#hint").css("display", "block").text("请输入验证码");
			$("#vertification").focus();
			return false;
		}
	}

	// 后台验证
	$.post(__URL("ADMIN_MAIN/login/login"), {
		"userName" : userName,
		"password" : password,
		"vertification" : vertification
	}, function(data) {
		if (data['code'] > 0) {
			$("#hint").css("display", "none");
			$(".sub_login").attr("disabled", "disabled");
			window.location.href = __URL("ADMIN_MAIN");
		} else {
			var error_num = {$login_verify_code['error_num']};
			if(error_num != 0 && data['error_num'] >= error_num){
				$(".verification-code-box").show();
				$("#verify_img").attr("src",'{:__URL('SHOP_MAIN/captcha?tag=1')}&send='+Math.random());
			}
			$("#txtValidate").val("");
			$("#hint").text(data['message']).show(); //  用户名密码提示
		}
	});
}

function ClearCookie() {
	var expires = new Date();
	expires.setTime(expires.getTime() - 1000);
	document.cookie = "appCode='';path=/;expires=" + expires.toGMTString() + "";
	document.cookie = "roleID='';path=/;expires=" + expires.toGMTString() + "";
	document.cookie = "parentMenuID='';path=/;expires=" + expires.toGMTString() + "";
	document.cookie = "currentMenuName='';path=/;expires=" + expires.toGMTString() + "";
}
</script>
</body>
</html>